package com.itheima.controller;

import com.itheima.service.SummaryInfoService;
import com.itheima.vo.ErrorResult;
import com.itheima.vo.SummaryInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @AUTHOR 李一军(13516354265 @ 163.com)
 * @VERSION V1.0.0
 * @DATE 2021/3/2 10:37
 */
@RestController
@RequestMapping("dashboard")
public class SummaryInfoController {
    @Autowired
    SummaryInfoService summaryInfoService;
    @GetMapping("summary")

    public ResponseEntity<Object> getSummaryInfo(@RequestHeader("Authorization") String token){

        SummaryInfo summaryInfo = summaryInfoService.getSummaryInfo(token);
        if(summaryInfo!=null){
            return ResponseEntity.ok(summaryInfo);
        }
        ErrorResult errorResult = ErrorResult.builder().errCode("000002").errMessage("获取活跃用户失败！").build();
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResult);
    }
	 @GetMapping("users")
    public ResponseEntity<Object> queryAddActive(@RequestHeader("Authorization") String token, @RequestParam Map<String,String> param){

        try {
            AddActiveInfo addActiveInfo = summaryInfoService.queryAddActive(token,param);
            if(addActiveInfo!=null){
                return ResponseEntity.ok(addActiveInfo);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }

        ErrorResult errorResult = ErrorResult.builder().errCode("000021").errMessage("团团提示:折线图图异常哟~~~！").build();
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResult);
    }
}
